//
//  MCBodyDataVc.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/7.
//

import UIKit
import SnapKit
import SnapKitExtend
import SwiftShow
import JXSegmentedView
import QMUIKit
import Kingfisher
import Toast_Swift
import RxSwift
import RxCocoa

// 屏幕宽度
let ScreenWidth = UIScreen.main.bounds.width
// 屏幕高度
let ScreenHeight = UIScreen.main.bounds.height

class MCBodyDataVc: MCBaseVc, JXSegmentedViewDelegate, JXSegmentedListContainerViewDataSource {
    
    
      
    
    var bodyInfoView:UIView!
    
    //身高
    var everyHeightSubView:UIView!
    //身高数值
    var everyHeightStr:String?
    
    //体重
    var everyWeightSubView:UIView!
    
    //体重数值
    var everyWeightStr:String?
    
    //体脂
    var everyTiSubView:UIView!
    
    //体脂数值
    var everyTiStr:String?
    
    //BMI
    var everyBmiSubView:UIView!
    
    //BMI
    var everyBmiStr:String?
    
    //胸围
    var bustView:UIView!
    
    //胸围数值
    var bustStr:String?
    
    //腰围
    var theWaistView:UIView!
    
    //腰围数值
    var waistStr:String?
    
    //腹围
    var abdominalView:UIView!
    
    //腹围数值
    var abdominalStr:String?
    
    //臀围
    var hipView:UIView!
    
    //臀围数值
    var hipStr:String?
    
    //手臂围
    var armView:UIView!
    //手臂围数值
    var armStr:String?
    
    //大腿围
    var thighView:UIView!
    
    //大腿围数值
    var thighStr:String?
    
    //小腿围
    var calfView:UIView!
    
    //小腿围数值
    var calfStr:String?
    
    
    let dispose:DisposeBag = DisposeBag()
    
    var userProfile:MCUserProfileModel!
    
    
    
    //身高
    lazy var lazyHeightRulerView:DYScrollRulerView = { [unowned self] in
        let unitStr     = "cm"
        let rulerHeight = DYScrollRulerView.rulerViewHeight
        var rulerView   = DYScrollRulerView.init(frame: CGRect.init(x: 5, y: 40, width: Int(ScreenWidth)-20, height: rulerHeight()), tminValue: 140, tmaxValue: 200, tstep: 1, tunit: unitStr, tNum:10, viewcontroller:self)
        rulerView.setDefaultValueAndAnimated(defaultValue: 170, animated: true)
        rulerView.bgColor       = UIColor.cyan
        rulerView.triangleColor = UIColor.white
        rulerView.delegate      = self
        rulerView.scrollByHand  = true
       return rulerView
    }()
    
    //体重
    lazy var lazyWeightRulerView:DYScrollRulerView = { [unowned self] in
        let unitStr     = "kg"
        let rulerHeight = DYScrollRulerView.rulerViewHeight
        var rulerView   = DYScrollRulerView.init(frame: CGRect.init(x: 5, y: 180, width: Int(ScreenWidth)-20, height: rulerHeight()), tminValue: 30, tmaxValue: 150, tstep: 0.1, tunit: unitStr, tNum:10, viewcontroller:self)
        rulerView.setDefaultValueAndAnimated(defaultValue: 90, animated: true)
        rulerView.bgColor       = UIColor.cyan
        rulerView.triangleColor = UIColor.white
        rulerView.delegate      = self
        rulerView.scrollByHand  = true
       return rulerView
    }()
    
    
    //体脂
    lazy var lazyBodyFatRulerView:DYScrollRulerView = { [unowned self] in
        let unitStr     = "%"
        let rulerHeight = DYScrollRulerView.rulerViewHeight
        var rulerView   = DYScrollRulerView.init(frame: CGRect.init(x: 5, y: 310, width: Int(ScreenWidth)-20, height: rulerHeight()), tminValue: 0, tmaxValue: 20, tstep: 0.1, tunit: unitStr, tNum:10, viewcontroller:self)
        rulerView.setDefaultValueAndAnimated(defaultValue: 10, animated: true)
        rulerView.bgColor       = UIColor.cyan
        rulerView.triangleColor = UIColor.white
        rulerView.delegate      = self
        rulerView.scrollByHand  = true
       return rulerView
    }()
    
   
    
    var segmentedDataSource:JXSegmentedTitleDataSource!
    let segmentedView = JXSegmentedView()
    lazy var listContainerView:JXSegmentedListContainerView! = {
        return JXSegmentedListContainerView(dataSource: self)
    }()
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.qmui_color(withHexString: "#F7F7F9")
        self.navigationItem.title = "身体数据"
        loadSubViews()
    
    }
    
    
    func loadSubViews() -> Void {
     
        //包裹
        let containerView = UIView.init()
        containerView.backgroundColor = UIColor.white
        containerView.layer.cornerRadius = 8
        containerView.layer.masksToBounds = true
        view.addSubview(containerView)
        containerView.snp.makeConstraints { make in
            make.left.equalTo(view.snp.left).offset(16)
            make.right.equalTo(view.snp.right).offset(-16)
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(25)
            make.height.equalTo(40)
        }
        
        
        //头像
        let headerImageView = UIImageView()
        headerImageView.kf.setImage(with: URL(string:userProfile.avatar ?? ""))
        containerView.addSubview(headerImageView)
        headerImageView.snp.makeConstraints { make in
            make.left.equalTo(containerView.snp.left).offset(10)
            make.centerY.equalTo(containerView.snp.centerY).offset(0)
            make.width.height.equalTo(30)
        }
        
        //昵称
        let nickNameLabel = UILabel()
        nickNameLabel.text = userProfile.name ?? ""
        nickNameLabel.font = UIFont(name: "PingFangSC-Semibold", size: 12)
        nickNameLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        containerView.addSubview(nickNameLabel)
        nickNameLabel.snp.makeConstraints { make in
            make.left.equalTo(headerImageView.snp.right).offset(10)
            make.centerY.equalTo(containerView.snp.centerY).offset(0)
            make.height.equalTo(18)
        }
        
        
        let dataBtn = QMUIButton.init()
        dataBtn.setTitle("数据统计", for: .normal)
        dataBtn.setTitleColor(UIColor.qmui_color(withHexString: "#333333"), for: .normal)
        dataBtn.titleLabel?.font = UIFont(name: "PingFangSC-Semibold", size: 12)
        dataBtn.backgroundColor = UIColor.qmui_color(withHexString: "#35DE94")
        dataBtn.layer.cornerRadius = 5
        dataBtn.layer.masksToBounds = true
        containerView.addSubview(dataBtn)
        dataBtn.snp.makeConstraints { make in
            make.right.equalTo(containerView.snp.right).offset(-16)
            make.centerY.equalTo(containerView.snp.centerY).offset(0)
            make.width.equalTo(58)
            make.height.equalTo(27)
        }
        dataBtn.rx.tap.subscribe(onNext: { event in
            let bodyDatastatisticsVc = MCBodyDataStatisticsVc.init()
            self.navigationController?.pushViewController(bodyDatastatisticsVc, animated: true)
        }).disposed(by: dispose)
        
        
        //身体信息
        bodyInfoView = UIView.init()
        bodyInfoView.backgroundColor = UIColor.white
        bodyInfoView.layer.cornerRadius = 5
        bodyInfoView.layer.masksToBounds = true
        view.addSubview(bodyInfoView)
        bodyInfoView.snp.makeConstraints { make in
            make.left.equalTo(view.snp.left).offset(16)
            make.right.equalTo(view.snp.right).offset(-16)
            make.top.equalTo(containerView.snp.bottom).offset(15)
            make.height.equalTo(47)
        }
        
        let bodyInfoTap = UITapGestureRecognizer.init(target: self, action: #selector(busyInfoAction))
        
        bodyInfoView.addGestureRecognizer(bodyInfoTap)
        
         
        //图标
        let iconImageView = UIImageView.init()
        iconImageView.image = UIImage(named: "mine_body_data_balck_image")
        view.addSubview(iconImageView)
        iconImageView.snp.makeConstraints { make in
            make.left.equalTo(view.snp.left).offset(0)
            make.top.equalTo(bodyInfoView.snp.bottom).offset(30)
        }
        
        
        
        
        getBodyData()
        
        
    }
    
    
    //通用内容
    func everyLoadSubView(_ title:String?,_ subTitle:String?) -> UIView {
        
        let bodyEveryInfoView = UIView.init()
        bodyEveryInfoView.backgroundColor = UIColor.white
        
        let titleBodyInfoLabel = QMUILabel.init()
        titleBodyInfoLabel.text = title
        titleBodyInfoLabel.font = UIFont(name: "PingFangSC-Regular", size: 12)
        titleBodyInfoLabel.textColor = UIColor.qmui_color(withHexString: "#999999")
        bodyEveryInfoView.addSubview(titleBodyInfoLabel)
        titleBodyInfoLabel.snp.makeConstraints { make in
            make.centerX.equalTo(bodyEveryInfoView.snp.centerX).offset(0)
            make.top.equalTo(bodyEveryInfoView.snp.top).offset(5)
        }
        
        let titleBodyLabel = QMUILabel.init()
        titleBodyLabel.text = subTitle
        titleBodyLabel.font = UIFont(name: "PingFangSC-Semibold", size:14)
        titleBodyLabel.textColor = UIColor.qmui_color(withHexString: "#10151C")
        bodyEveryInfoView.addSubview(titleBodyLabel)
        titleBodyLabel.snp.makeConstraints { make in
            make.centerX.equalTo(bodyEveryInfoView.snp.centerX).offset(0)
            make.top.equalTo(titleBodyInfoLabel.snp.bottom).offset(0)
            make.height.equalTo(20)
        }
        
        return bodyEveryInfoView
        
    }
    
    
    @objc func numberOfLists(in listContainerView:JXSegmentedListContainerView) -> Int {
        return 7
    }
    
    @objc func listContainerView(_ listContainerView:JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        let bodySelectRulerVc = MCBodySelectRulerVc.init()
        
        bodySelectRulerVc.selectDataInfoHandler = { handler in
            
            switch index {
            case 0:
                self.bustStr = String(describing: handler)
            case 1:
                self.waistStr = String(describing: handler)
            case 2:
                self.abdominalStr = String(describing: handler)
                
            case 3:
                self.hipStr = String(describing: handler)
            case 4:
                self.armStr = String(describing: handler)
            case 5:
                self.thighStr = String(describing: handler)
                self.thighStr = String(describing: handler)
            case 6:
                self.calfStr = String(describing: handler)
            default:
                print(handler)
            }
            
            
        }
        
        
        
        return bodySelectRulerVc
        
    }
    
    
    //通用内容
    func everyBMILoadSubView(_ title:String?,_ subTitle:String?,_ content:String?) -> UIView {
        
        let bodyEveryInfoView = UIView.init()
        
        bodyEveryInfoView.backgroundColor = UIColor.white
        bodyEveryInfoView.layer.cornerRadius = 5
        bodyEveryInfoView.layer.masksToBounds = true
        
        let titleBodyInfoLabel = QMUILabel.init()
        titleBodyInfoLabel.text = title
        titleBodyInfoLabel.font = UIFont(name: "PingFangSC-Regular", size: 12)
        titleBodyInfoLabel.textColor = UIColor.qmui_color(withHexString: "#999999")
        bodyEveryInfoView.addSubview(titleBodyInfoLabel)
        titleBodyInfoLabel.snp.makeConstraints { make in
            make.centerX.equalTo(bodyEveryInfoView.snp.centerX).offset(0)
            make.top.equalTo(bodyEveryInfoView.snp.top).offset(5)
        }
        
        let titleBodyLabel = MCPaddingLabel.init()
        titleBodyLabel.text = subTitle
        titleBodyLabel.font = UIFont(name: "PingFangSC-Semibold", size:14)
        titleBodyLabel.textColor = UIColor.qmui_color(withHexString: "#10151C")
        bodyEveryInfoView.addSubview(titleBodyLabel)
        titleBodyLabel.snp.makeConstraints { make in
            make.centerX.equalTo(bodyEveryInfoView.snp.centerX).offset(0)
            make.top.equalTo(titleBodyInfoLabel.snp.bottom).offset(0)
            make.height.equalTo(20)
        }
        
        let titleBMILabel = MCPaddingLabel.init()
        titleBMILabel.leftInset = 2
        titleBMILabel.rightInset = 2
        titleBMILabel.topInset = 1
        titleBMILabel.bottomInset = 1
        titleBMILabel.text = content
        titleBMILabel.font = UIFont(name: "PingFangSC-Regular", size: 10)
        titleBMILabel.backgroundColor = UIColor.qmui_color(withHexString: "#35DE94")?.withAlphaComponent(0.1)
        titleBMILabel.textColor = UIColor.qmui_color(withHexString: "#109B5E")
        bodyEveryInfoView.addSubview(titleBMILabel)
        titleBMILabel.snp.makeConstraints { make in
            make.left.equalTo(titleBodyLabel.snp.right).offset(4)
            make.centerY.equalTo(titleBodyLabel.snp.centerY).offset(0)
            
        }
        
        return bodyEveryInfoView
        
    }
    
    
    
    //身体各种数据
    func loadBodyDataSubViews(_ title:String?,_ subTitle:String?) -> UIView {
        let bodyEveryInfoView = UIView.init()
        
        bodyEveryInfoView.backgroundColor = UIColor.white
        
        bodyEveryInfoView.layer.cornerRadius = 8
        bodyEveryInfoView.layer.masksToBounds = true
        
        let titleBodyInfoLabel = QMUILabel.init()
        titleBodyInfoLabel.text = title
        titleBodyInfoLabel.font = UIFont(name: "PingFangSC-Regular", size: 12)
        titleBodyInfoLabel.textColor = UIColor.qmui_color(withHexString: "#999999")
        bodyEveryInfoView.addSubview(titleBodyInfoLabel)
        titleBodyInfoLabel.snp.makeConstraints { make in
            make.centerY.equalTo(bodyEveryInfoView.snp.centerY).offset(0)
            make.left.equalTo(bodyEveryInfoView.snp.left).offset(10)
        }
        
        let titleBodyLabel = QMUILabel.init()
        titleBodyLabel.text = subTitle
        titleBodyLabel.font = UIFont(name: "PingFangSC-Semibold", size: 14)
        titleBodyLabel.textColor = UIColor.qmui_color(withHexString: "#10151C")
        bodyEveryInfoView.addSubview(titleBodyLabel)
        titleBodyLabel.snp.makeConstraints { make in
            make.centerY.equalTo(bodyEveryInfoView.snp.centerY).offset(0)
            make.right.equalTo(bodyEveryInfoView.snp.right).offset(-10)
        }
        
        return bodyEveryInfoView
    }
    
    
    
    
    @objc func bustAction() -> Void {
        handleShowContentView()
    }
    
   @objc func busyInfoAction() -> Void {
       loadBodyDataSubViews()
    }
    
    
    //输入数据
    func handleShowContentView() -> Void {
        
        let contentView = UIView.init()
        contentView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: 450)
        contentView.backgroundColor = UIColor.white
      
        let backBtn = QMUIButton.init()
        backBtn.setImage(UIImage(named: "mine_close_light_gray_image"), for: .normal)
        contentView.addSubview(backBtn)
        backBtn.snp.makeConstraints { make in
            make.left.equalTo(contentView.snp.left).offset(16)
            make.top.equalTo(contentView.snp.top).offset(15)
            make.height.width.equalTo(20)
        }
        
        
        let titleCenterLabel = QMUILabel.init()
        titleCenterLabel.text = "输入数据"
        titleCenterLabel.font = UIFont.systemFont(ofSize: 17)
        titleCenterLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        contentView.addSubview(titleCenterLabel)
        titleCenterLabel.snp.makeConstraints { make in
            make.centerX.equalTo(contentView.snp.centerX).offset(0)
            make.top.equalTo(contentView.snp.top).offset(15)
        }
        
        
        let enterBackBtn = QMUIButton.init()
        enterBackBtn.setTitle("确定", for: .normal)
        enterBackBtn.titleLabel?.font = UIFont(name: "PingFangSC-Regular", size: 13)
        enterBackBtn.setTitleColor(UIColor.qmui_color(withHexString: "#35DE94"), for: .normal)
        enterBackBtn.addTarget(self, action: #selector(enterBackSender), for: .touchUpInside)
        contentView.addSubview(enterBackBtn)
        enterBackBtn.snp.makeConstraints { make in
            make.right.equalTo(contentView.snp.right).offset(-16)
            make.top.equalTo(contentView.snp.top).offset(15)
            make.height.equalTo(20)
        }
        
        
        segmentedDataSource = JXSegmentedTitleDataSource()
        segmentedDataSource.isTitleColorGradientEnabled = true
        
        segmentedView.dataSource = segmentedDataSource
        segmentedView.delegate = self
        
       
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorWidth = 20
        segmentedView.indicators = [indicator]
        contentView.addSubview(segmentedView)
        
        segmentedView.listContainer = listContainerView
        
        contentView.addSubview(listContainerView)
        
        segmentedView.snp.makeConstraints { make in
            make.left.equalTo(contentView.snp.left).offset(0)
            make.right.equalTo(contentView.snp.right).offset(0)
            make.top.equalTo(backBtn.snp.bottom).offset(60.0)
            make.height.equalTo(50.auto())
        }
        
        listContainerView.snp.makeConstraints { make in
            make.left.equalTo(contentView.snp.left).offset(0)
            make.right.equalTo(contentView.snp.right).offset(0)
            make.top.equalTo(segmentedView.snp.bottom).offset(0.0)
            make.bottom.equalTo(contentView.snp.bottom).offset(0.0)
        }
        
        self.segmentedDataSource.titles = ["胸围","腰围","腹围","臀围","手臂围","大腿围","小腿围"]
        
        Show.pop(contentView){(config) in config.showAnimateType = .bottom;config.clickOutHidden = true}
    }
    
        
    ///身体的各种数据参数
    func loadBodyDataSubViews() -> Void {
        
        let contentView = UIView.init()
        contentView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: 450)
        contentView.backgroundColor = UIColor.white
        
       
        contentView.addSubview(lazyHeightRulerView)
        
        
        contentView.addSubview(lazyWeightRulerView)
        
        let WeightLabel = QMUILabel.init()
        WeightLabel.text = "体重 kg"
        WeightLabel.font = UIFont(name: "PingFangSC-Semibold", size: 14)
        WeightLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        contentView.addSubview(WeightLabel)
        WeightLabel.snp.makeConstraints { make in
            make.left.equalTo(contentView.snp.left).offset(16)
            make.top.equalTo(lazyHeightRulerView.snp.bottom).offset(16)
        }
        
        contentView.addSubview(lazyBodyFatRulerView)
        
        let bodyFatLabel = QMUILabel.init()
        bodyFatLabel.text = "体脂 %"
        bodyFatLabel.font = UIFont(name: "PingFangSC-Semibold", size: 14)
        bodyFatLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        contentView.addSubview(bodyFatLabel)
        bodyFatLabel.snp.makeConstraints { make in
            make.left.equalTo(contentView.snp.left).offset(16)
            make.top.equalTo(lazyWeightRulerView.snp.bottom).offset(16)
          
        }
        
        let backBtn = QMUIButton.init()
        backBtn.setImage(UIImage(named: "mine_close_light_gray_image"), for: .normal)
        contentView.addSubview(backBtn)
        backBtn.snp.makeConstraints { make in
            make.left.equalTo(contentView.snp.left).offset(16)
            make.top.equalTo(contentView.snp.top).offset(15)
            make.height.width.equalTo(20)
        }
        
        let enterBackBtn = QMUIButton.init()
        enterBackBtn.setTitle("确定", for: .normal)
        enterBackBtn.titleLabel?.font = UIFont(name: "PingFangSC-Regular", size: 13)
        enterBackBtn.setTitleColor(UIColor.qmui_color(withHexString: "#35DE94"), for: .normal)
        enterBackBtn.addTarget(self, action: #selector(enterBackSender), for: .touchUpInside)
        contentView.addSubview(enterBackBtn)
        enterBackBtn.snp.makeConstraints { make in
            make.right.equalTo(contentView.snp.right).offset(-16)
            make.top.equalTo(contentView.snp.top).offset(15)
            make.height.equalTo(20)
        }
        
        
        let titleCenterLabel = QMUILabel.init()
        titleCenterLabel.text = "输入数据"
        titleCenterLabel.font = UIFont(name: "PingFangSC-Semibold", size: 14)
        titleCenterLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        contentView.addSubview(titleCenterLabel)
        
        titleCenterLabel.snp.makeConstraints { make in
            make.centerX.equalTo(contentView.snp.centerX).offset(0)
            make.top.equalTo(contentView.snp.top).offset(15)
        }
        
        let heightLabel = QMUILabel.init()
        heightLabel.text = "身高 cm"
        heightLabel.font = UIFont(name: "PingFangSC-Semibold", size: 14)
        heightLabel.textColor = UIColor.qmui_color(withHexString: "#333333")
        contentView.addSubview(heightLabel)
        heightLabel.snp.makeConstraints { make in
            make.left.equalTo(contentView.snp.left).offset(16)
            make.top.equalTo(titleCenterLabel.snp.bottom).offset(16)
        }
        
        Show.pop(contentView){(config) in config.showAnimateType = .bottom;config.clickOutHidden = true}
        
    }
    
    @objc func enterBackSender() -> Void {
        self.sendResult()
    }
    
    
    
    func getBodyData() -> Void {
        NetWorkRequest(MCBodyDataApi.getBodyData) { ResponseModel in
            let bodyDataInfoModel = mineBodyDataInfoModel.init(JSONString: ResponseModel.dataString)
            
            
            if bodyDataInfoModel?.height == nil {
                self.everyHeightSubView = self.everyLoadSubView("身高", "0cm")
                self.bodyInfoView.addSubview(self.everyHeightSubView)
                self.everyHeightStr = "0"
            }else{
                self.everyHeightSubView = self.everyLoadSubView("身高", "\(String(describing:( bodyDataInfoModel?.height)!))cm")
                self.bodyInfoView.addSubview(self.everyHeightSubView)
                self.everyHeightStr = bodyDataInfoModel?.height
            }
            
            
            
            if bodyDataInfoModel?.weight == nil {
                self.everyWeightSubView = self.everyLoadSubView("体重", "0kg")
                self.bodyInfoView.addSubview(self.everyWeightSubView)
                
                self.everyWeightStr = "0"
            }else{
                self.everyWeightSubView = self.everyLoadSubView("体重", "\(String(describing:( bodyDataInfoModel?.weight)!))kg")
                self.bodyInfoView.addSubview(self.everyWeightSubView)
                
                self.everyWeightStr = bodyDataInfoModel?.weight
            }
            
            if bodyDataInfoModel?.fat == nil {
                
                self.everyTiSubView = self.everyLoadSubView("体脂", "0")
                self.bodyInfoView.addSubview(self.everyTiSubView)
                
                self.everyTiStr = "0"
                
                if bodyDataInfoModel?.bmiStatus == nil {
                    self.everyBmiSubView = self.everyBMILoadSubView("BMI", "","")
                    self.bodyInfoView.addSubview(self.everyBmiSubView)
                }else{
                    if bodyDataInfoModel?.bmiStatus == 0 {
                        self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","较低")
                        self.bodyInfoView.addSubview(self.everyBmiSubView)
                    }else if bodyDataInfoModel?.bmiStatus == 1 {
                        self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","健康")
                        self.bodyInfoView.addSubview(self.everyBmiSubView)
                    }else if bodyDataInfoModel?.bmiStatus == 2 {
                        self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","超重")
                        self.bodyInfoView.addSubview(self.everyBmiSubView)
                    }else if bodyDataInfoModel?.bmiStatus == 3 {
                        self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","肥胖")
                        self.bodyInfoView.addSubview(self.everyBmiSubView)
                    }else {
                        self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","")
                        self.bodyInfoView.addSubview(self.everyBmiSubView)
                    }
                }
                
                
            }else{
                self.everyTiSubView = self.everyLoadSubView("体脂", "\(String(describing:( bodyDataInfoModel?.fat)!))")
                self.bodyInfoView.addSubview(self.everyTiSubView)
                
                self.everyTiStr = bodyDataInfoModel?.fat
                
                if bodyDataInfoModel?.bmiStatus == 0 {
                    self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","较低")
                    self.bodyInfoView.addSubview(self.everyBmiSubView)
                }else if bodyDataInfoModel?.bmiStatus == 1 {
                    self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","健康")
                    self.bodyInfoView.addSubview(self.everyBmiSubView)
                }else if bodyDataInfoModel?.bmiStatus == 2 {
                    self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","超重")
                    self.bodyInfoView.addSubview(self.everyBmiSubView)
                }else if bodyDataInfoModel?.bmiStatus == 3 {
                    self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","肥胖")
                    self.bodyInfoView.addSubview(self.everyBmiSubView)
                }else {
                    self.everyBmiSubView = self.everyBMILoadSubView("BMI", "\(String(describing:( bodyDataInfoModel?.bmi)!))","")
                    self.bodyInfoView.addSubview(self.everyBmiSubView)
                }
                
            }
            
            
            let arr = [self.everyHeightSubView,self.everyWeightSubView,self.everyTiSubView,self.everyBmiSubView]
            arr.snp.distributeViewsAlong(axisType: .horizontal,fixedSpacing: 0,leadSpacing: 0,tailSpacing: 0)
            arr.snp.makeConstraints { make in
                make.top.equalTo(0)
                make.height.equalTo(47)
            }
            
            
            let rightBodyView = UIView.init()
            self.view.addSubview(rightBodyView)
            rightBodyView.snp.makeConstraints { make in
                make.right.equalTo(self.view.snp.right).offset(0)
                make.bottom.equalTo(self.view.snp.bottom).offset(-100)
                make.top.equalTo(self.bodyInfoView.snp.bottom).offset(50)
                make.left.equalTo(self.view.snp.left).offset(ScreenWidth / 2)
            }
            
            if bodyDataInfoModel?.bust == nil {
                
                self.bustView = self.loadBodyDataSubViews("胸围", "0cm")
                rightBodyView.addSubview(self.bustView)
                
                self.bustStr = "0"
                
            }else {
                self.bustView = self.loadBodyDataSubViews("胸围", "\(String(describing:( bodyDataInfoModel?.bust)!))cm")
                rightBodyView.addSubview(self.bustView)
                
                self.bustStr = bodyDataInfoModel?.bust
            }
            
            
            
            let bustTap = UITapGestureRecognizer.init(target: self, action: #selector(self.bustAction))
            
            self.bustView.addGestureRecognizer(bustTap)
            
            
            if bodyDataInfoModel?.waist == nil {
                self.theWaistView = self.loadBodyDataSubViews("腰围", "0cm")
                rightBodyView.addSubview(self.theWaistView)
                self.waistStr = "0"
            }else {
                self.theWaistView = self.loadBodyDataSubViews("腰围", "\(String(describing:( bodyDataInfoModel?.waist)!))cm")
                rightBodyView.addSubview(self.theWaistView)
                self.waistStr = bodyDataInfoModel?.waist
            }
            
            
            
            let waistTap = UITapGestureRecognizer.init(target: self, action: #selector(self.bustAction))
            self.theWaistView.addGestureRecognizer(waistTap)
            
            
            if bodyDataInfoModel?.abdomen == nil {
                self.abdominalView = self.loadBodyDataSubViews("腹围", "0cm")
                rightBodyView.addSubview(self.abdominalView)
                
                self.abdominalStr = "0"
            }else {
                self.abdominalView = self.loadBodyDataSubViews("腹围", "\(String(describing:( bodyDataInfoModel?.abdomen)!))cm")
                rightBodyView.addSubview(self.abdominalView)
                
                self.abdominalStr = bodyDataInfoModel?.abdomen
            }
            
            
            
            let adbominalTap = UITapGestureRecognizer.init(target: self, action: #selector(self.bustAction))
            self.abdominalView.addGestureRecognizer(adbominalTap)
            
            
            if bodyDataInfoModel?.pygal == nil {
                self.hipView = self.loadBodyDataSubViews("臀围", "0cm")
                rightBodyView.addSubview(self.hipView)
                self.hipStr = "0"
            }else {
                self.hipView = self.loadBodyDataSubViews("臀围", "\(String(describing:( bodyDataInfoModel?.pygal)!))cm")
                rightBodyView.addSubview(self.hipView)
                self.hipStr = bodyDataInfoModel?.abdomen
            }
            
            
            
            let hipTap = UITapGestureRecognizer.init(target: self, action: #selector(self.bustAction))
            self.hipView.addGestureRecognizer(hipTap)
            
            if bodyDataInfoModel?.arm == nil {
                self.armView = self.loadBodyDataSubViews("手臂围", "0cm")
                rightBodyView.addSubview(self.armView)
                self.armStr = "0"
            }else {
                self.armView = self.loadBodyDataSubViews("手臂围", "\(String(describing:( bodyDataInfoModel?.arm)!))cm")
                rightBodyView.addSubview(self.armView)
                self.armStr = bodyDataInfoModel?.arm
            }
            
           
            
            let armTap = UITapGestureRecognizer.init(target: self, action: #selector(self.bustAction))
            
            self.armView.addGestureRecognizer(armTap)
            
            
            if bodyDataInfoModel?.thigh == nil {
                self.thighView = self.loadBodyDataSubViews("大腿围", "0cm")
                rightBodyView.addSubview(self.thighView)
                self.thighStr = "0"
            }else {
                self.thighView = self.loadBodyDataSubViews("大腿围", "\(String(describing:( bodyDataInfoModel?.thigh)!))cm")
                rightBodyView.addSubview(self.thighView)
                self.thighStr = bodyDataInfoModel?.thigh
            }
            
          
            
            let thighTap = UITapGestureRecognizer.init(target: self, action: #selector(self.bustAction))
            self.thighView.addGestureRecognizer(thighTap)
            
            if bodyDataInfoModel?.shank == nil {
                self.calfView = self.loadBodyDataSubViews("小腿围", "0cm")
                rightBodyView.addSubview(self.calfView)
                self.calfStr = "0"
            } else {
                self.calfView = self.loadBodyDataSubViews("小腿围", "\(String(describing:( bodyDataInfoModel?.shank)!))cm")
                rightBodyView.addSubview(self.calfView)
                self.calfStr = bodyDataInfoModel?.shank
            }
            
            let shankTap = UITapGestureRecognizer.init(target: self, action: #selector(self.bustAction))
            self.calfView.addGestureRecognizer(shankTap)
            
            let bodyDataArr = [self.bustView,self.theWaistView,self.abdominalView,self.hipView,self.armView,self.thighView,self.calfView]
            
            bodyDataArr.snp.distributeViewsAlong(axisType: .vertical,fixedItemLength: 40,leadSpacing: 0,tailSpacing: 0)
            
            bodyDataArr.snp.makeConstraints { make in
                make.width.equalTo(138)
                make.right.equalTo(-16)
            }
            
        } failureCallback: { ResponseModel in
            self.view.makeToast("网络失败",position: .center)
        }
    }
    
    
    
    
    //动态设置数据
    func sendResult() -> Void {
        setBodyData(height: self.everyHeightStr, weight: self.everyWeightStr, fat: self.everyTiStr, bust: self.bustStr, waist: self.waistStr, adbomen: self.abdominalStr, pypal: self.hipStr, arm: self.armStr, thigh: self.thighStr, shank: self.calfStr)
    }
    
    //设置数据
    func setBodyData(height:String?,weight:String?,fat:String?,bust:String?,waist:String?,adbomen:String?,pypal:String?,arm:String?,thigh:String?,shank:String?) -> Void{
        NetWorkRequest(MCBodyDataApi.setBodyData(height: height, weight: weight, fat: fat, bust: bust, waist: waist, adbomen: adbomen, pypal: pypal, arm: arm, thigh: thigh, shank: shank)) { ResponseModel in
            if ResponseModel.code == 200 {
                self.view.makeToast("修改成功",position: .center)
            }else{
                self.view.makeToast(ResponseModel.message,position: .center)
            }
            
            
        } failureCallback: { ResponseModel in
            self.view.makeToast("网络失败",position: .center)
        }
    }
    
}




extension MCBodyDataVc:DYScrollRulerDelegate {
    func dyScrollRulerViewValueChange(rulerView: DYScrollRulerView, value: Float) {
        
        if self.lazyHeightRulerView == rulerView {
            self.everyHeightStr = "\(value)"
        }else if self.lazyWeightRulerView == rulerView {
            self.everyWeightStr = "\(value)"
        }else if self.lazyBodyFatRulerView == rulerView {
            self.everyTiStr = "\(value)"
        }
        
       
    }
}
